package com.study.ju.service.impl;

import com.study.ju.service.transactionaltest.TestAService;
import com.study.ju.service.transactionaltest.TestBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Created by tao on 2018/8/4.
 */
@Service
public class TestAImpl implements TestAService {
    @Autowired
    private TestBService testBService;

    @Transactional
    public void insetATest() {
        try {
            System.out.println("biz层 正常执行-开始");
            for (int j = 0; j < 8; j++) {
                testBService.testBInsert(j, j + "姓名");
              /*  if (j == 3) {
                    int i = 1 / 0;// 此处会产生异常
                }*/
            }

        } catch (Exception e) {
            System.out.println("异常日志处理-A");
        }
        System.out.println("biz层 正常执行");

    }

    @Transactional
    @Override
    public void insetATestNoExceptionNoTryCatch() {
        System.out.println("biz层 正常执行-开始");
        for (int j = 0; j < 8; j++) {
            testBService.testBInsertExceptionAndNoTryCatch(j, j + "姓名");
        }
        System.out.println("biz层 正常执行");
    }

    @Transactional
    @Override
    public void insetATestNoExceptionTryCatchtestBInsertExceptionAndNoTryCatch() {
        System.out.println("biz层 正常执行-开始");
        for (int j = 0; j < 8; j++) {

            try {
                testBService.testBInsertExceptionAndNoTryCatch(j, j + "姓名");

            } catch (Exception e) {
                System.out.println("异常日志处理-A");
            }
        }

        System.out.println("biz层 正常执行");
    }

    @Transactional
    @Override
    public void insetATestExceptionNoTryCatch() {

    }

    @Transactional
    @Override
    public void insetATestExceptionTryCatch() {

    }

}
